﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;

namespace Com.CMS263.DAO
{
    public class MessageDAO:BaseService
    {
        public MessageDAO() { }
        public IList<Message> GetListByPager(int userid, int page, int pagesize)
        {
            string hql = " from Message where 1=1";
            if (userid != 0)
            {
                hql += " and UserId=" + userid;
            }

            hql += " order by AddDate Desc";
            try
            {
                if (page == -1)
                {
                    return FindList<Message>(hql, null, null, null);
                }
                else
                {
                    return FindList<Message>(hql, null, (page - 1) * pagesize, pagesize);
                }
            }
            catch (Exception)
            {

                return null;
            }

        }

        public int GetListByPager(int typeid)
        {
            string hql = "select count(*) from Message where 1=1";
            if (typeid != 0)
            {
                hql += " and UserId=" + typeid;
            }

            try
            {
                return Convert.ToInt32(GetValue(hql));
            }
            catch (Exception)
            {
                return 0;
            }

        }
    }
}
